package com.atguigu.java.ai.langchain4j.tools;

import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import dev.langchain4j.agent.tool.ToolMemoryId;
import org.springframework.stereotype.Component;

/**
 * @author zhaoyf
 * @version 1.0
 * @description 数学计算工具类
 * @date 2025/8/1 21:10
 */
@Component
public class CalculatorTools {
    /**
     * 加法运算
     * @return 和
     */
    @Tool(name = "加法运算",value = "将两个参数a和b相加，并返回结果")
    double sum(
            @ToolMemoryId int memoryId,
            @P(value = "加数1", required = true) double a,
            @P(value = "加数2", required = true) double b) {
        System.out.println("调用加法运算，memoryId=="+memoryId);
        return a + b;
    }

    /**
     * 平方根运算
     * @return 平方根
     */
    @Tool(name = "平方根运算",value = "对参数x求平方根运算，返回结果")
    double squareRoot(@ToolMemoryId int memoryId,double x) {
        System.out.println("调用平方根运算，memoryId=="+memoryId);
        return Math.sqrt(x);
    }
}
